package cn.xaut.周赛.m227;

/**
 * 5674. 构造字典序最大的合并字符串
 */
public class demo5674 {

    public String largestMerge(String word1, String word2) {
        
        StringBuilder res = new StringBuilder();
        while (!"".equals(word1) && !"".equals(word2)) {
            if (word1.compareTo(word2) > 0) {
                res.append(word1.charAt(0));
                word1 = word1.substring(1);
            } else {
                res.append(word2.charAt(0));
                word2 = word2.substring(1);
            }
        }
        res.append("".equals(word1) ? word2 : word1);
        return res.toString();
    }

    public static void main(String[] args) {

        System.out.println(new demo5674().largestMerge("cabaa", "bcaaa"));
        System.out.println(new demo5674().largestMerge("abcabc", "abdcaba"));
    }
}
